def jostphus(n,m):
    people = list(range(n))
    m -= 1
    k = m % n
    while (len(people)>1):
        del people[k]
        k = (k+m) %n
    return people[0]
